package com.szholly.data.general;

import java.io.Serializable;

import com.szholly.utils.util.DateUtils;
import com.szholly.utils.util.StringUtils;

/**
 * 类功能说明 定义全局数据库参数类
 */
public class GlobalParameter implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**
	 * 定义空参数对象
	 */
	public static final GlobalParameter[] Empty = new GlobalParameter[]{};

	/**
	 * 参数名称
	 */
	private String paraName;

	/**
	 * 参数值
	 */
	private Object paraValue;
	
	/**
	 * 参数值_字符串
	 * 添加原因(paraValue是Object,在dwr中转换不了)
	 */
	private String paraValueStr;
	
	/**
	 * 字段名称
	 */
	private String fieldName;
	
	/**
	 * 字段类型
	 */
	private String fieldType;

	/**
	 * 是否为输出参数
	 */
	private Boolean outParameter;

	
	public GlobalParameter() {
	}

	public GlobalParameter(String paraName, Object paraValue){
		this.paraName = paraName;
		this.paraValue = paraValue;
	}
	

	public GlobalParameter(String paraName, Object paraValue,String fieldName,String fieldType) {
		this.paraName = paraName;
		this.paraValue = paraValue;
		this.fieldName = fieldName;
		this.fieldType = fieldType;
		this.outParameter = false;
	}

	public String getFieldName() {
		return fieldName;
	}

	public void setFieldName(String fieldName1) {
		this.fieldName = fieldName1;
	}

	public String getFieldType() {
		return fieldType;
	}

	public void setFieldType(String fieldType1) {
		this.fieldType = fieldType1;
	}

	public String getParaName() {
		return paraName;
	}

	public void setParaName(String value) {
		paraName = value;
	}

	public Object getParaValue() {
		//转义
		if(!StringUtils.IsNullOrEmpty(this.getParaValueStr())){
			if(StringUtils.IsNullOrEmpty(this.getFieldType()) || "STRING".equals(this.getFieldType().toUpperCase())){
				return this.getParaValueStr();
			}else if((this.getFieldType().toUpperCase()).startsWith("INT")){
				return new Integer(this.getParaValueStr());
			}else if("DOUBLE".equals(this.getFieldType().toUpperCase())){
				return new Double(this.getParaValueStr());
			}else if("FLOAT".equals(this.getFieldType().toUpperCase())){
				return new Float(this.getParaValueStr());
			}else if("DATE".equals(this.getFieldType().toUpperCase())){
				String str = this.getParaValueStr(); 
				str = str.replace("#BDATE", "")
				.replace("#EDATE", "")
				.replace("#EDATETIME", "")
				.replace("#SYSDATETIME#", DateUtils.convertDateToString(new java.util.Date()));
				this.setParaValueStr(str);
				return this.getParaValueStr(); 
			}else if("DATETIME".equals(this.getFieldType().toUpperCase())){
				String str = this.getParaValueStr(); 
				str = str.replace("#BDATE", "")
				.replace("#EDATE", "")
				.replace("#EDATETIME", "")
				.replace("#SYSDATETIME#", DateUtils.convertDateToString(new java.util.Date()));
				this.setParaValueStr(str);
				return this.getParaValueStr();
			}else{
				return this.getParaValueStr();
			}
		}
		return paraValue;
	}

	public void setParaValue(Object value) {
		this.paraValue = value;
	}

	public String getParaValueStr() {
		return paraValueStr;
	}

	public void setParaValueStr(String paraValueStr) {
		this.paraValueStr = paraValueStr;
	}

	public Boolean getOutParameter() {
		return outParameter;
	}

	public void setOutParameter(Boolean value) {
		outParameter = value;
	}
}
